﻿//********************************************************************************//
//创建日期：<创建日期，2016-09-19>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：采灌计划 采灌计划下达
//********************************************************************************//

using System;
using System.Web.UI;
using BLL;
using BLL.Access;
using DevExpress.Web;

namespace Web.Pages.QuShui.DiXiaS.JiHuaGL.CaiGuanJH
{
    public partial class CaiGuanJHXD : BasePage
    {
        #region 方法

        /// <summary>
        ///     初始化数据
        /// </summary>
        private void InitData()
        {
            var year = "";
            var year1 = "";
            var year2 = "";
            _SpHelper.P_QSJH_MAXYEAR("QS_JH_NIANJIH", out year1);
            var dt = _CANSHUBLL.SelectQS_CANSHUBsDynamic("i_jlzt=0 and S_MINGCHENG=\'WaterYear\' or S_MIAOSHU=\'水量年\'",
                null);
            year2 = dt.Rows.Count > 0 ? dt.Rows[0]["S_ZHI"].ToString() : "";
            if (year1 == "" || year1 == null)
                year = year2;
            else
                year = (Convert.ToInt32(year1) + 1).ToString();
            if (Convert.ToInt32(year) <= Convert.ToInt32(year2) + 1)
                txtV.Text = year;
            else
                txtV.Text = "";
        }

        #endregion

        #region 属性

        #endregion

        #region 变量

        /// <summary>
        ///     存储过程执行类
        /// </summary>
        private readonly SpHelper _SpHelper = new SpHelper();

        /// <summary>
        ///     操作日志BLL
        /// </summary>
        private SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        /// <summary>
        ///     参数bll
        /// </summary>
        private readonly QS_CANSHUBBLL _CANSHUBLL = new QS_CANSHUBBLL();

        /// <summary>
        ///     年计划bll
        /// </summary>
        private readonly QS_JH_NIANJIHBLL _CGJHBLL = new QS_JH_NIANJIHBLL();

        #endregion

        #region 事件

        /// <summary>
        ///     页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack) InitData();
        }

        /// <summary>
        ///     绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }


        /// <summary>
        ///     放弃
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            InitData();
        }

        /// <summary>
        ///     响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, CallbackEventArgs e)
        {
            //int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            var year = Convert.ToInt32(txtV.Text.Trim());
            var msg = "";
            if (e.Parameter == "yz1")
            {
                var dt = _CGJHBLL.SelectQS_JH_NIANJIHsDynamic(string.Format("I_Y={0} and i_jlzt=0", txtV.Text.Trim()),
                    null);
                if (dt.Rows.Count > 0)
                    msg = "true";
                else
                    msg = "false";
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "yz2")
            {
                //根据sname 是否 采灌井，以及年份来判断是否用户都已经制定计划
                var result = "";
                _SpHelper.P_QSJH_JIHUAGLXD("采灌井", year.ToString(), out result);
                msg = result == "0" ? "true" : "false";
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "xdjh")
            {
                //下达采灌计划
                _SpHelper.P_QSJH_XIADAJH(1, year, out msg); //1 下达成功
                e.Result = e.Parameter + "|0|" + msg;
            }
        }

        #endregion
    }
}